package dao

import (
	"driver_certification_srv/config"
	"gorm.io/gorm"
)

type Driver struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;comment:'用户名'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
}

func (d *Driver) DriverCreate() (uint, string) {
	var driver Driver
	config.DB.Where("username=?", d.Username).First(&driver)
	if driver.ID == 0 {
		err := config.DB.Create(&d).Error
		if err != nil {
			return 0, "司机注册失败"
		}
		return d.ID, ""
	} else {
		if driver.Password != d.Password {
			return 0, "密码错误"
		}
		return driver.ID, ""
	}
}
